import os

def restrict_input(_input, _low, _high):
    if(_input<_low or _input >_high):
        # print("Invalid Input")
        return False
    return True

# general-purpose sort function. 
def sort_cards(cards):
        temp_hand = []
        temp_card_suit = ''
        temp_card_value = 1
        for card in cards:
            if card[1] == 'J':
                temp_card_value = 11
            elif card[1] == 'Q':
                temp_card_value = 12
            elif card[1] == 'K':
                temp_card_value = 13
            elif card[1] == 'A':
                temp_card_value = 14
            else:
                temp_card_value = int(card[1])

            temp_card_suit = card[0]
            temp_hand.append((temp_card_suit, temp_card_value))
            
        new_hand = sorted(temp_hand, key=lambda temp_hand: temp_hand[-1])

        # Now to repurpose these lists
        temp_hand = new_hand
        new_hand = []

        for card in temp_hand:
            if card[1] == 11:
                temp_card_value = 'J'
            elif card[1] == 12:
                temp_card_value = 'Q'
            elif card[1] == 13:
                temp_card_value = 'K'
            elif card[1] == 14:
                temp_card_value = 'A'
            else:
                temp_card_value = str(card[1])

            temp_card_suit = card[0]
            new_hand.append((temp_card_suit, temp_card_value))
        return new_hand



def clear_screen(numlines=100):
    """Clear the console.

    numlines is an optional argument used only as a fall-back.
    """
    if os.name == "posix":
        # Unix/Linux/MacOS/BSD/etc
        os.system('clear')
    elif os.name in ("nt", "dos", "ce"):
        # DOS/Windows
        os.system('CLS')
    else:
        # Fallback for other operating systems.
        for i in range(numlines):
            print('\n', end = '')
